import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSessionStore = defineStore('session', () => {
    // 当前会话ID
    const currentSessionId = ref(null)

    // 历史会话列表
    const sessions = ref([
    ])

    // 设置当前会话
    function setCurrentSession(id) {
        currentSessionId.value = id
    }

    // 新增一个会话
    function createNewSession() {
        const newId = (sessions.value.length + 1).toString()
        const newSession = { id: newId, title: `新对话 ${newId}` }
        sessions.value.push(newSession)
        currentSessionId.value = newId
        return newId
    }

    return {
        currentSessionId,
        sessions,
        setCurrentSession,
        createNewSession
    }
})